﻿/**
 * ...
 * @author Sergey Mamyan
 */


package tx.squirrel.neko.core.model;

import neko.db.Object;

class Installation extends Object {
	static var TABLE_IDS = ["appId", "userId"];
	public static var manager = new InstallationManager();
	
	public var userId:String;
	public var appId:String;
	public var role:String;
	public var installTime:Date;
	public var loginTime:Date;
	public var loginCount:Int;
	
	public static function install(app:Application, user:User):Installation {
		var inst:Installation = new Installation();
		inst.appId = app.id;
		inst.userId = user.id;
		inst.insert();
		return inst;
	}
	
	public function new() {
		super();
		installTime = Date.now();
		loginTime = Date.now();
		loginCount = 0;
	}
	
	override public function update():Void {
		this.loginTime = Date.now();
		this.loginCount = loginCount + 1;
		super.update();
	}
	
}

class InstallationManager extends neko.db.Manager < Installation > {
	
	public function new () {
		super(Installation);
	}
}